<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>

    function MyEvent(){
        this.message = {};

        this.add = function(type, cb){
            if(this.message[type]){
                this.message[type].push(cb);
            }else{
                this.message[type] = [cb];
            }
        }

        this.emit = function(type){
            if(!this.message[type]) return;
            this.message[type].forEach(val=>{
                val();
            })
        }

        this.remove = function(type, cb){
            if(!this.message[type]) return;
            const index = this.message[type].indexOf(cb);
            if(index !== -1){
                this.message[type].splice(index, 1);
            }
        }
    }

    const event = new MyEvent();

    event.add("abc", fn1);
    event.add("abc", fn3);
    event.add("abc", fn4);
    
    event.add("qwe", fn2);
    
    event.add("asd", fn3);

    event.remove("abc", fn3);

    event.emit("abc");

    event.emit("qwe");


    function fn1(){ console.log(1) }
    function fn2(){ console.log(2) }
    function fn3(){ console.log(3) }
    function fn4(){ console.log(4) }
    function fn5(){ console.log(5) }
</script>
</html>